package org.pattern.abstractFactory.util;

import org.pattern.abstractFactory.model.ActionFigure;


public class ConsoleActionFigureSimulator {
	private ActionFigureFactory actionFigureFactory;
	
	public ConsoleActionFigureSimulator(ActionFigureFactory actionFigureFactory){
		this.actionFigureFactory = actionFigureFactory;
	}
	
	public void fight(){
		ActionFigure hero = actionFigureFactory.createHero();
		ActionFigure villain  = actionFigureFactory.createVillain();

		System.out.println(hero.getName() + " Health: " + hero.getHealth() + " vs. " + villain.getName() + " Health: " + villain.getHealth() + "\n");

		int i = 1;
		while( !hero.isDead() && !villain.isDead()){
			System.out.println("------- Round: " + i++ + " -------");
			hero.defend(villain.attack()); 
			villain.defend(hero.attack());
			System.out.println(hero.getName() + " has " + hero.getHealth() + " health left");
			System.out.println(villain.getName() + " has " + villain.getHealth() + " health left");
			System.out.println("-------------------------\n");
		}
				
		if(hero.isDead()){
			System.out.println(hero.getName() + " was slayed by: " + villain.getName());
		}

		if(villain.isDead()){
			System.out.println(villain.getName() + " was slayed by: " + hero.getName());
		}
	}
}
